import {reqCreateUser, reqDuplicateRemoval} from '@/api'
import { Message } from 'element-ui';
import route from '@/route';
export default({
    namespaced:true,
    actions:{
        async getUserNameList(context,value){
            let result=await reqDuplicateRemoval();
            if(result.code==='200'){
                context.commit('getRequestStateCode',result.code);
                context.commit('getUserNameList',result.other);
            }else{
                context.commit('getRequestStateCode',result.code)
                Message({
                    message: '警告!'+'['+result.code+']'+'['+result.message+']',
                    type: 'warning'
                })
                return;
            }
        },
        async createUser(context,value){
            let result=await reqCreateUser(value);
            if(result.code==='200'){
                context.commit('createUser')
            }else{
                Message({
                    message: '警告!'+'['+result.code+']'+'['+result.message+']',
                    type: 'warning'
                })
                return;
            }
        }
    },
    mutations:{
        getRequestStateCode(state,value){
            state.requestCode=value;
        },
        getUserNameList(state,value){
            state.accountList=value
        },
        createUser(){
            Message({
                message:'新建账号成功！',
                type:'success'
            })
            setTimeout(()=>{
                route.replace({
                    name:'Login'
                })
            },1000)
        }
    },
    state:{
        requestCode:'',
        accountList:[]
    },
    getters:{
        
    }
})